package com.letv.android.client.controller;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.letv.android.client.constant.ChannelConstant;
import com.letv.android.client.task.RequestTopicPlayTask;
import com.letv.android.client.utils.AlbumLaunchUtils;
import com.letv.android.client.webview.LetvWebViewActivity;
import com.letv.android.young.client.R;
import com.letv.core.bean.AlbumNew;
import com.letv.core.bean.ChannelListBean;
import com.letv.core.bean.ChannelListBean.Channel;
import com.letv.core.bean.HomeMetaData;
import com.letv.core.bean.LiveRemenListBean.LiveRemenBaseBean;
import com.letv.core.bean.UserBean;
import com.letv.core.bean.channel.ChannelHomeSimpleBlock;
import com.letv.core.constant.PlayConstant;
import com.letv.core.db.PreferencesManager;
import com.letv.core.utils.LetvUtils;
import com.letv.core.utils.LogInfo;
import com.letv.core.utils.NetworkUtils;
import com.ledim.utils.ToastUtil;
import java.util.ArrayList;

public class UIControllerUtils {

    /*
     * 跳转到我的积分页面参数
     */
    private static UserBean mUser = null;

    private static String mPageId = "";

    /**
     * 外跳phone内置浏览器（v5.5版本更换为qq浏览器）
     *
     * @param context
     * @param url
     */
    @Deprecated
    public static void gotoWeb(Context context, String url) {
        Intent intent = new Intent(Intent.ACTION_VIEW);

        intent.setData(Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY |
                Intent.FLAG_FROM_BACKGROUND);
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(intent);
        } else {
            ToastUtil.toast("跳转失败，请确认是否安装浏览器");
        }
    }

    public static void setUser(UserBean user) {
        mUser = user;
    }

    /**
     * 频道id
     */
    public static final String ENTERTAINMENT_CHANNEL_ID = "03";
    public static final String OTHER_CHANNEL_ID = "11";
    public static final String MUSIC_CHANNEL_ID = "09";
    public static final String SPORTS_CHANNEL_ID = "04";
    private static final String PAGE_ID_4D = "1002984593";

    public static String channelIdTochannelType(String channelID) {
        LogInfo.log("UIControllerUtils", "channelIdTochannelType channelID : " + channelID);
        String channelType = PlayConstant.CHANNEL_TYPE_VALUE_SPORTS;

        if (channelID.equals(ENTERTAINMENT_CHANNEL_ID)) {
            channelType = PlayConstant.CHANNEL_TYPE_VALUE_ENT;
        } else if (channelID.equals(OTHER_CHANNEL_ID)) {
            channelType = PlayConstant.CHANNEL_TYPE_VALUE_OTHER;
        } else if (channelID.equals(MUSIC_CHANNEL_ID)) {
            channelType = PlayConstant.CHANNEL_TYPE_VALUE_MUSIC;
        } else if (channelID.equals(SPORTS_CHANNEL_ID)) {
            channelType = PlayConstant.CHANNEL_TYPE_VALUE_SPORTS;
        }
        LogInfo.log("UIControllerUtils", "channelIdTochannelType channelType : " + channelType);
        return channelType;
    }

    public static boolean isFeeLive(HomeMetaData block) {
        boolean res = false;
        String liveid = block.getLiveid();
        String zhiboid = block.getId();
        if (!TextUtils.isEmpty(liveid) && liveid.length() >= 2 && !TextUtils.isEmpty(zhiboid)) {
            res = true;
        }
        return res;
    }

    public static boolean isFeeLive(ChannelHomeSimpleBlock block) {
        boolean res = false;
        String liveid = block.getLiveid();
        String zhiboid = block.getId();
        if (!TextUtils.isEmpty(liveid) && liveid.length() >= 2 && !TextUtils.isEmpty(zhiboid)) {
            res = true;
        }
        return res;
    }

    public static void gotoActivity(final Context context, HomeMetaData block, int index,
                                    int from) {
        /*
         * Add the judge condition by chenhong on 2014/08/19
         */
        if (!NetworkUtils.isNetworkAvailable(context) &&
                block.getAt() != HomeMetaData.GOTO_PAGE_PAY) {
            ToastUtil.toast(R.string.load_data_no_net);
        }

        LogInfo.log("gotoActivity", "gotoActivity HomeMetaData block.getAt() " + block.getAt());
        switch (block.getAt()) {
            case HomeMetaData.GOTO_PLAYER_HALF:
                if (block.getType() == AlbumNew.Type.TOPIC_MANG) {

                    RequestTopicPlayTask mRequestTopicPlayTask =
                            new RequestTopicPlayTask(context, block.getZid());
                    mRequestTopicPlayTask.requestTopicPlayTask();
                } else {

                    // BasePlayActivity.launch(context, block.getPid(),
                    // block.getVid(), from);
                    AlbumLaunchUtils.launch(context, block.getPid(), block.getVid(), from, null);
                }
                break;
            case HomeMetaData.GOTO_PLAYER_FULL:
                AlbumLaunchUtils.launch(context, 0, block.getVid(), from, null);
                break;
            case HomeMetaData.GOTO_PLAYER_LIVE:
                String tvCode = block.getStreamCode();
                String liveUrl = block.getStreamUrl();
                String zhiboId = block.getId();
                String name = block.getNameCn();
                String liveid = block.getLiveid();
                // BuNo:7252,hzz
                boolean pay = LiveRemenBaseBean.IS_PAY.equals(String.valueOf(block.getPay()));
                handleFocusLiveLaunch(context, tvCode, liveUrl, zhiboId, name, liveid, pay);
                // end
                break;
            case HomeMetaData.GOTO_WEB_OUTER:
                String webUrl = block.getWebUrl();
                if (webUrl == null) {
                    return;
                }
                webUrl = LetvUtils.checkUrl(webUrl);
                UIControllerUtils.gotoWeb(context, webUrl);
                break;
            case HomeMetaData.GOTO_WEB_INNER:
                String webViewUrl = block.getWebViewUrl();
                if (webViewUrl == null) {
                    return;
                }

                webViewUrl = LetvUtils.checkUrl(webViewUrl);
                // 2014-01-03 ljnalex modify start 入口更改，我是歌手进入特定webview
                // if (webViewUrl.contains("letv")) {
                // LetvSignerWebViewActivity.launch(context, webViewUrl,
                // block.getNameCn());
                // } else {
                // LetvWebViewActivity.launch(context, webViewUrl, block.getNameCn());
                // }
                LogInfo.log("+-->", "---GOTO_WEB_INNER---");
                LetvWebViewActivity.launch(context, webViewUrl, block.getNameCn(), 1);
                break;
            case HomeMetaData.GOTO_PAGE_RECOMMEND:
                // 精品推荐页面
                //                RecommendFragmentActivity.launch(context);
                break;
            case HomeMetaData.GOTO_PAGE_CHANNEL:
                // 频道二级页
                from = PlayConstant.LAUNCH_FROM_HOME == from ? ChannelConstant.FROM_HOME : from;
                //                MainActivity.getInstance().gotoChannelByCid(String.valueOf(block.getCid()), block.getPageid(), from);
                break;
            case HomeMetaData.GOTO_PAGE_VIP:
                // 会员频道
                from = PlayConstant.LAUNCH_FROM_HOME == from ? ChannelConstant.FROM_HOME : from;
                //                MainActivity.getInstance().gotoChannelByCid(String.valueOf(AlbumNew.Channel.TYPE_VIP),
                //                        block.getPageid(), from);
                break;
            case HomeMetaData.GOTO_PAGE_PAY:
                // 收银台
                //                if (PreferencesManager.getInstance().isLogin() && PreferencesManager.getInstance().isVip()) {
                //                    VipProductsActivity.launch(context, context.getResources().getString(R.string.pim_vip_recharge),
                //                            PreferencesManager.getInstance().isSViP());
                //                } else {
                //                    VipProductsActivity.launch(context, context.getResources().getString(R.string.pim_vip_good_title));
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_WO_UNION:
                // 联通订购页面
                //                if (!PreferencesManager.getInstance().isLogin()) {
                //                    LetvLoginActivity.launch((Activity) context);
                //                    StatisticsUtils.staticticsInfoPost(context, "71", null, 1, -1, null, null, null, null, null);
                //                } else {
                //                    if (PreferencesManager.getInstance().getUserOrderWo()) { // 退订
                //                        if (NetworkUtils.getNetworkType() == NetworkUtils.OPERATOR_UNKNOWN) {
                //                            ToastUtils.showToast(context, R.string.wo_flow_flow_no_net_toast);
                //                            return;
                //                        }
                //                        // 短信取号退订 防止是wifi
                //                        Class clazz_wfm = JarLoader.loadClass(context, JarConstant.LETV_WO_NAME,
                //                                JarConstant.LETV_WO_PACKAGENAME, "WoFlowManager");
                //                        IWoFlowManager woFlowManager = (IWoFlowManager) JarLoader.invokeStaticMethod(clazz_wfm,
                //                                "getInstance", null, null);
                //                        woFlowManager.showSmsSureDialog(context, new WoInterface.LetvWoFlowListener() {
                //                            @Override
                //                            public void onResponseOrderInfo(boolean isSupportProvince, boolean isOrder,
                //                                    boolean isUnOrderSure, String freeUrl, boolean isSmsSuccess) {
                //                                if (isSmsSuccess) {
                //                                    // 去退订
                //                                    Intent intent = new Intent(context, LetvWoFlowActivity.class);
                //                                    context.startActivity(intent);
                //                                } else {
                //                                    // 短信取号不成功
                //                                }
                //                            }
                //                        });
                //                    }
                // sumin.zhao 595因为特殊原因需要去掉联通订购流程
                // else { // 订购
                // if (NetworkUtils.getNetTypeForWo()) {
                // WoManager.getInstance().checkProviceOpenWoFlow(context,
                // new WoInterface.LetvWoFlowListener() {
                // @Override
                // public void onResponseOrderInfo(boolean isSupportProvince, boolean isOrder,
                // boolean isUnOrderSure, String freeUrl, boolean isSmsSuccess) {
                // if (isSupportProvince) {
                // Intent intent = new Intent(context, LetvWoFlowActivity.class);
                // context.startActivity(intent);
                // } else {
                // ToastUtils.showToast(context,
                // R.string.wo_flow_flow_not_support_province_toast);
                // }
                // }
                // }, true);
                // } else if (NetworkUtils.getNetType() != NetworkUtils.NETTYPE_NO) {
                // ToastUtils.showToast(context, R.string.wo_flow_flow_toast);
                // } else if (NetworkUtils.getNetType() == NetworkUtils.NETTYPE_NO) {
                // ToastUtils.showToast(context, R.string.wo_flow_flow_no_net_toast);
                // }
                // }
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_SCORE:
                // 积分页面
                //                if (NetworkUtils.isNetworkAvailable()) {
                //                    if (PreferencesManager.getInstance().isLogin()) {
                //                        Intent intent = new Intent(context, PointsActivtiy.class);
                //                        intent.putExtra("title", context.getResources().getString(R.string.pim_vip_good_title));
                //                        if (mUser != null) {
                //                            intent.putExtra("User", mUser);
                //                        } else {
                //                            UserBean user = new UserBean();
                //                            user.setPicture(PreferencesManager.getInstance().getPicture());
                //                            user.setNickname(PreferencesManager.getInstance().getNickName());
                //                            user.setUsername(PreferencesManager.getInstance().getUserName());
                //                            user.setScore(PreferencesManager.getInstance().getScore());
                //                            intent.putExtra("User", user);
                //                        }
                //                        context.startActivity(intent);
                //                    } else {
                //                        LetvLoginActivity.launch((Activity) context, LoginConstant.LOGIN_MY_POINTS);
                //                        StatisticsUtils.staticticsInfoPost(context, "71", null, 1, -1, null, null, null, null, null);
                //                    }
                //                } else {
                //                    UIsUtils.showToast(context, R.string.net_error);
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_LOGIN:
                // 登录页面
                //                if (!PreferencesManager.getInstance().isLogin()) {
                //                    // LoginMainActivity.launch(context);
                //                    LetvLoginActivity.launch((Activity) context);
                //                } else {
                //                    // SettingCenterFragmentActivity.launch((Activity) context,
                //                    // From.PersonalInfo.getInt());
                //                    SettingsMainActivity.launch(context);
                //                }
                break;
            default:
                break;
        }
    }

    static void handleFocusLiveLaunch(Context context, String tvCode, String liveUrl,
                                      String zhiboId, String name, String liveid, boolean pay) {
        // zhiboId = "3020141107155913";
        // liveid = "0900120140120006";
        // pay = true;
        LogInfo.log("letv_live",
                "handleFocusLiveLaunch tvCode = " + tvCode + " , zhiboId = " + zhiboId +
                        " , name = " + name + " , liveid = " + liveid + " , pay = " + pay +
                        " , liveUrl is null = " + (TextUtils.isEmpty(liveUrl)));
        if (!TextUtils.isEmpty(liveid) && liveid.length() > 1) {// 有liveid，能进半屏
            String channelId = liveid.substring(0, 2);
            String channelType = channelIdTochannelType(channelId);
            //            LiveLaunchUtils.launchFocusPicLive(context, 0, channelType, tvCode, liveUrl, pay, zhiboId);
        } else {// 没有liveid，只进全屏
            if (pay && PreferencesManager.getInstance(context).isTestApi()) {
                ToastUtil.toast("test msg : liveid为空！");
            }
            if (!TextUtils.isEmpty(zhiboId)) {
                //                LiveLaunchUtils.launchLiveById(context, zhiboId);
            } else {
                // if (!pay) {
                if (!TextUtils.isEmpty(liveUrl)) {

                    //                    LiveLaunchUtils.launchLives(context, null, tvCode, liveUrl, true, PlayConstant.LAUNCH_FROM_CHANNEL,
                    //                            name);

                }
                // } else {
                // if (PreferencesManager.getInstance().isTestApi()) {
                // UIsUtils.showToast(context, "这是付费视频，只填了url？无法鉴权");
                // } else {
                // LogInfo.log("LetvHttp", "-------- 尼玛付费视频，你只传个url？连直播id都没有鉴个p权啊");
                // }
                // }
            }
        }
    }

    public static void gotoActivity(final Context context, ChannelHomeSimpleBlock block,
                                    boolean isDobly, String pageId) {
        mPageId = pageId;
        gotoActivity(context, block, isDobly);
    }

    public static void gotoActivity(final Context context, ChannelHomeSimpleBlock block,
                                    boolean isDobly) {
        if (!NetworkUtils.isNetworkAvailable(context) &&
                block.getAt() != HomeMetaData.GOTO_PAGE_PAY) {
            ToastUtil.toast(R.string.load_data_no_net);
        }
        LogInfo.log("gotoActivity",
                "gotoActivity ChannelHomeSimpleBlock " + block.getNameCn() + " block.getAt() = " +
                        block.getAt());
        LogInfo.log("gotoActivity",
                "gotoActivity ChannelHomeSimpleBlock " + block.getNameCn() + " block.getAt() = " +
                        block.getAt());
        switch (block.getAt()) {
            case HomeMetaData.GOTO_PLAYER_HALF:
                if (block.getType() == AlbumNew.Type.TOPIC_MANG) {
                    RequestTopicPlayTask mRequestTopicPlayTask =
                            new RequestTopicPlayTask(context, block.getZid());
                    mRequestTopicPlayTask.requestTopicPlayTask();
                    // MainLaunchUtils.launchToTopicPlay(context, Long.parseLong(block.getZid()), false);
                } else {
                    AlbumLaunchUtils.launch(context, block.getPid(), block.getVid(), isDobly, PlayConstant.LAUNCH_FROM_CHANNEL);
                }
                break;
            case HomeMetaData.GOTO_PLAYER_FULL:
                if (isDobly) {
                    AlbumLaunchUtils.launch(context, 0, block.getVid(), isDobly, PlayConstant.LAUNCH_FROM_CHANNEL);
                } else {
                    AlbumLaunchUtils.launch(context, 0, block.getVid(), PlayConstant.LAUNCH_FROM_CHANNEL, null);
                }
                break;
            case HomeMetaData.GOTO_PLAYER_LIVE:
                if (PAGE_ID_4D.equals(mPageId) || "1003041295".equals(mPageId)) {// test
                    AlbumLaunchUtils.launch(context, block.getPadPic(), block.getStreamUrl(), PlayConstant.PLAY_MODE_NATIVE);
                    mPageId = "";
                    break;
                }
                String tvCode = block.getStreamCode();
                String liveUrl = block.getStreamUrl();
                String zhiboId = block.getId();
                String name = block.getNameCn();
                String liveid = block.getLiveid();
                boolean pay = LiveRemenBaseBean.IS_PAY.equals(String.valueOf(block.getPay()));
                handleFocusLiveLaunch(context, tvCode, liveUrl, zhiboId, name, liveid, pay);
                break;
            case HomeMetaData.GOTO_WEB_OUTER:
                String webUrl = block.getWebUrl();
                if (webUrl == null) {
                    return;
                }
                webUrl = LetvUtils.checkUrl(webUrl);
                UIControllerUtils.gotoWeb(context, webUrl);
                break;
            case HomeMetaData.GOTO_WEB_INNER:
                String webViewUrl = block.getWebViewUrl();
                if (webViewUrl == null) {
                    return;
                }
                webViewUrl = LetvUtils.checkUrl(webViewUrl);
                LogInfo.log("+-->", "---HomeMetaData.GOTO_WEB_INNER---");
                // LetvSearchWebViewActivity.launch(context, webViewUrl,
                // block.getNameCn(), "1");
                LetvWebViewActivity.launch(context, webViewUrl, block.getNameCn(), 1);
                break;
            case HomeMetaData.GOTO_PAGE_RECOMMEND:
                // RecommendFragmentActivity.launch(context);
                break;
            case HomeMetaData.GOTO_PAGE_CHANNEL:
                // 频道二级页
                //                if (context instanceof MainActivity) {
                //                    ((MainActivity) context).gotoChannelByCid(String.valueOf(block.getCid()), block.getId(), 6);
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_VIP:
                // 会员频道
                //                if (context instanceof MainActivity) {
                //                    ((MainActivity) context).gotoChannelByCid(String.valueOf(AlbumNew.Channel.TYPE_VIP), block.getId(),
                //                            6);
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_PAY:
                // 收银台
                //                if (PreferencesManager.getInstance().isLogin() && PreferencesManager.getInstance().isVip()) {
                //                    VipProductsActivity.launch(context, context.getResources().getString(R.string.pim_vip_recharge),
                //                            PreferencesManager.getInstance().isSViP());
                //                } else {
                //                    VipProductsActivity.launch(context, context.getResources().getString(R.string.pim_vip_good_title));
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_WO_UNION:
                // 联通订购页面
                //                if (!PreferencesManager.getInstance().isLogin()) {
                //                    LetvLoginActivity.launch((Activity) context);
                //                    StatisticsUtils.staticticsInfoPost(context, "71", null, 1, -1, null, null, null, null, null);
                //                } else {
                //                    if (PreferencesManager.getInstance().getUserOrderWo()) { // 退订
                //                        if (NetworkUtils.getNetworkType() == NetworkUtils.OPERATOR_UNKNOWN) {
                //                            ToastUtils.showToast(context, R.string.wo_flow_flow_no_net_toast);
                //                            return;
                //                        }
                //                        // 短信取号退订 防止是wifi
                //                        Class clazz_wfm = JarLoader.loadClass(context, JarConstant.LETV_WO_NAME,
                //                                JarConstant.LETV_WO_PACKAGENAME, "WoFlowManager");
                //                        IWoFlowManager woFlowManager = (IWoFlowManager) JarLoader.invokeStaticMethod(clazz_wfm,
                //                                "getInstance", null, null);
                //                        woFlowManager.showSmsSureDialog(context, new WoInterface.LetvWoFlowListener() {
                //                            @Override
                //                            public void onResponseOrderInfo(boolean isSupportProvince, boolean isOrder,
                //                                    boolean isUnOrderSure, String freeUrl, boolean isSmsSuccess) {
                //                                if (isSmsSuccess) {
                //                                    // 去退订
                //                                    Intent intent = new Intent(context, LetvWoFlowActivity.class);
                //                                    context.startActivity(intent);
                //                                } else {
                //                                    // 短信取号不成功
                //                                }
                //                            }
                //                        });
                //                    }
                //                    // sumin.zhao 595因为联通初始化有问题所以要先去掉联通订购
                //                    // else { // 订购
                //                    // if (NetworkUtils.getNetTypeForWo()) {
                //                    // WoManager.getInstance().checkProviceOpenWoFlow(context,
                //                    // new WoInterface.LetvWoFlowListener() {
                //                    // @Override
                //                    // public void onResponseOrderInfo(boolean isSupportProvince, boolean isOrder,
                //                    // boolean isUnOrderSure, String freeUrl, boolean isSmsSuccess) {
                //                    // if (isSupportProvince) {
                //                    // Intent intent = new Intent(context, LetvWoFlowActivity.class);
                //                    // context.startActivity(intent);
                //                    // } else {
                //                    // ToastUtils.showToast(context,
                //                    // R.string.wo_flow_flow_not_support_province_toast);
                //                    // }
                //                    // }
                //                    // }, true);
                //                    // } else if (NetworkUtils.getNetType() != NetworkUtils.NETTYPE_NO) {
                //                    // ToastUtils.showToast(context, R.string.wo_flow_flow_toast);
                //                    // } else if (NetworkUtils.getNetType() == NetworkUtils.NETTYPE_NO) {
                //                    // ToastUtils.showToast(context, R.string.wo_flow_flow_no_net_toast);
                //                    // }
                //                    // }
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_SCORE:
                // 积分页面
                //                if (NetworkUtils.isNetworkAvailable()) {
                //                    if (PreferencesManager.getInstance().isLogin()) {
                //                        Intent intent = new Intent(context, PointsActivtiy.class);
                //                        intent.putExtra("title", context.getResources().getString(R.string.pim_vip_good_title));
                //                        if (mUser != null) {
                //                            intent.putExtra("User", mUser);
                //                        } else {
                //                            UserBean user = new UserBean();
                //                            user.setPicture(PreferencesManager.getInstance().getPicture());
                //                            user.setNickname(PreferencesManager.getInstance().getNickName());
                //                            user.setUsername(PreferencesManager.getInstance().getUserName());
                //                            user.setScore(PreferencesManager.getInstance().getScore());
                //                            intent.putExtra("User", user);
                //                        }
                //                        context.startActivity(intent);
                //                    } else {
                //                        LetvLoginActivity.launch((Activity) context, LoginConstant.LOGIN_MY_POINTS);
                //                        StatisticsUtils.staticticsInfoPost(context, "71", null, 1, -1, null, null, null, null, null);
                //                    }
                //                } else {
                //                    ToastUtils.showToast(context, R.string.net_error);
                //                }
                break;
            case HomeMetaData.GOTO_PAGE_LOGIN:
                // 登录页面
                //                if (!PreferencesManager.getInstance().isLogin()) {
                //                    // LoginMainActivity.launch(context);
                //                    LetvLoginActivity.launch((Activity) context);
                //                } else {
                //                    // SettingCenterFragmentActivity.launch((Activity) context,
                //                    // From.PersonalInfo.getInt());
                //                    SettingsMainActivity.launch(context);
                //                }
                break;
            default:
                break;
        }
    }

    @SuppressLint({ "StringFormatMatches", "NewApi" })
    public static void showSubTitle(Context context, HomeMetaData block, TextView titleView,
                                    TextView subTitleView, View titleLayout) {
        if (context == null || titleView == null || subTitleView == null) {
            return;
        }

        if (TextUtils.isEmpty(block.getNameCn())) {
            titleLayout.setVisibility(View.GONE);
            subTitleView.setVisibility(View.GONE);
            titleView.setVisibility(View.GONE);
            return;
        } else {
            titleLayout.setVisibility(View.VISIBLE);
        }

        subTitleView.setAlpha(0.8f);
        titleView.setVisibility(View.VISIBLE);
        titleView.setMaxLines(1);
        titleView.setText(block.getNameCn());

        // LabelMap labelMap = LetvApplication.getInstance().getLabelMap();
        switch (block.getCid()) {
            case AlbumNew.Channel.TYPE_TV:
            case AlbumNew.Channel.TYPE_CARTOON:
                subTitleView.setVisibility(View.VISIBLE);
                // 电视剧、动漫专辑非正片显示副标题
                // if (block.getType() == AlbumNew.Type.VRS_MANG
                // && (TextUtils.isEmpty(block.getAlbumType()) || LetvMediaDictionary.LabelTag.LABEL_KEY_180001
                // .equals(block.getAlbumType()))
                // && block.getIsEnd() == 0
                // && !TextUtils.isEmpty(block.getNowEpisodes())
                // && !"0".equals(block.getNowEpisodes())) {// 专辑
                // titleView.setSingleLine(true);
                // titleView.setMaxLines(1);
                // subTitleView
                // .setText(context.getString(
                // R.string.channel_list_currcount,
                // block.getNowEpisodes()));
                // } else {// 视频或专题
                // if (!TextUtils.isEmpty(block.getSubTitle())) {
                // titleView.setSingleLine(true);
                // titleView.setMaxLines(1);
                // subTitleView.setVisibility(View.VISIBLE);
                // subTitleView.setText(block.getSubTitle());
                // } else {
                // subTitleView.setVisibility(View.GONE);
                // titleView.setSingleLine(false);
                // titleView.setMaxLines(2);
                // }
                // }
                break;
            case AlbumNew.Channel.TYPE_TVSHOW:
                // 综艺单视频非正片不显示副标题
                if (!TextUtils.isEmpty(block.getSubTitle())) {
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_PE:
                // 栏目：显示副标题；非栏目：不显示副标题
                if (block.isVarietyShow() && !TextUtils.isEmpty(block.getSubTitle())) {
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_MUSIC:
                // 音乐区块 获取singer字段显示，区分推荐数据和CMS数据（version>=5.5）
                if (block.getType() == AlbumNew.Type.VRS_ONE) {// 视频
                    String subTitle = null;
                    if (block.isRec()) {
                        // 推荐数据
                        subTitle = TextUtils.isEmpty(block.getSubTitle()) ? block.getSinger()
                                                                          : block.getSubTitle();
                    } else {
                        // CMS数据
                        subTitle = block.getSubTitle();
                    }

                    if (!TextUtils.isEmpty(subTitle)) {
                        titleView.setSingleLine(true);
                        titleView.setMaxLines(1);
                        subTitleView.setVisibility(View.VISIBLE);
                        subTitleView.setText(subTitle);
                    } else {
                        subTitleView.setVisibility(View.GONE);
                        titleView.setSingleLine(false);
                        titleView.setMaxLines(2);
                    }
                } else {
                    if (block.isRec()) {
                        subTitleView.setVisibility(View.GONE);
                        titleView.setSingleLine(false);
                        titleView.setMaxLines(2);
                    } else {
                        if (!TextUtils.isEmpty(block.getSubTitle())) {
                            titleView.setSingleLine(true);
                            titleView.setMaxLines(1);
                            subTitleView.setVisibility(View.VISIBLE);
                            subTitleView.setText(block.getSubTitle());
                        } else {
                            subTitleView.setVisibility(View.GONE);
                            titleView.setSingleLine(false);
                            titleView.setMaxLines(2);
                        }
                    }
                }
                break;
            case AlbumNew.Channel.TYPE_JOY:
                subTitleView.setVisibility(View.GONE);
                titleView.setSingleLine(false);
                titleView.setMaxLines(2);
                break;
            case AlbumNew.Channel.TYPE_MOVIE:
                if (!TextUtils.isEmpty(block.getSubTitle())) {// 副标题不为空
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_DOCUMENT_FILM:
                if (block.getType() == AlbumNew.Type.VRS_MANG &&
                        !TextUtils.isEmpty(block.getSubTitle())) {// 专辑且副标题不为空
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            default:
                if (!TextUtils.isEmpty(block.getSubTitle())) {
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
        }
    }

    @SuppressLint({ "StringFormatMatches", "NewApi" })
    public static void showSubTitleForChannel(Context context, ChannelHomeSimpleBlock block,
                                              TextView titleView, TextView subTitleView) {
        if (context == null || subTitleView == null) {
            return;
        }
        subTitleView.setAlpha(0.8f);
        titleView.setVisibility(View.VISIBLE);
        titleView.setText(block.getNameCn() + " ");

        // LabelMap labelMap = LetvApplication.getInstance().getLabelMap();
        switch (block.getCid()) {
            case AlbumNew.Channel.TYPE_TV:
            case AlbumNew.Channel.TYPE_CARTOON:
                subTitleView.setVisibility(View.VISIBLE);
                // 电视剧、动漫专辑非正片显示副标题
                // if (block.getType() == AlbumNew.Type.VRS_MANG
                // && (TextUtils.isEmpty(block.getAlbumType()) || LetvMediaDictionary.LabelTag.LABEL_KEY_180001
                // .equals(block.getAlbumType()))
                // && block.getIsEnd() == 0
                // && !TextUtils.isEmpty(block.getNowEpisodes() + "")
                // && block.getNowEpisodes() != 0) {// 专辑) {//专辑
                // subTitleView
                // .setText(context.getString(
                // R.string.channel_list_currcount,
                // block.getNowEpisodes()));
                // } else {// 视频或专题
                // if (!TextUtils.isEmpty(block.getSubTitle())) {
                // titleView.setSingleLine(true);
                // titleView.setMaxLines(1);
                // subTitleView.setVisibility(View.VISIBLE);
                // subTitleView.setText(block.getSubTitle());
                // } else {
                // subTitleView.setVisibility(View.GONE);
                // titleView.setSingleLine(false);
                // titleView.setMaxLines(2);
                // }
                // }
                break;
            case AlbumNew.Channel.TYPE_TVSHOW:
                // 综艺单视频非正片不显示副标题
                if (!TextUtils.isEmpty(block.getSubTitle())) {
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_PE:
                // 栏目：显示副标题；非栏目：不显示副标题
                if (block.isVarietyShow() && !TextUtils.isEmpty(block.getSubTitle())) {
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_MUSIC:
                // 音乐区块 获取singer字段显示，区分推荐数据和CMS数据（version>=5.5）
                if (block.getType() == AlbumNew.Type.VRS_ONE) {// 视频
                    String subTitle = null;
                    if (block.isRec()) {
                        // 推荐数据
                        subTitle = TextUtils.isEmpty(block.getSubTitle()) ? block.getSinger()
                                                                          : block.getSubTitle();
                    } else {
                        // CMS数据
                        subTitle = block.getSubTitle();
                    }

                    if (!TextUtils.isEmpty(subTitle)) {
                        titleView.setSingleLine(true);
                        titleView.setMaxLines(1);
                        subTitleView.setVisibility(View.VISIBLE);
                        subTitleView.setText(subTitle);
                    } else {
                        subTitleView.setVisibility(View.GONE);
                        titleView.setSingleLine(false);
                        titleView.setMaxLines(2);
                    }
                } else {
                    if (block.isRec()) {
                        subTitleView.setVisibility(View.GONE);
                        titleView.setSingleLine(false);
                        titleView.setMaxLines(2);
                    } else {
                        if (!TextUtils.isEmpty(block.getSubTitle())) {
                            titleView.setSingleLine(true);
                            titleView.setMaxLines(1);
                            subTitleView.setVisibility(View.VISIBLE);
                            subTitleView.setText(block.getSubTitle());
                        } else {
                            subTitleView.setVisibility(View.GONE);
                            titleView.setSingleLine(false);
                            titleView.setMaxLines(2);
                        }
                    }
                }
                break;
            case AlbumNew.Channel.TYPE_JOY:
                subTitleView.setVisibility(View.GONE);
                titleView.setSingleLine(false);
                titleView.setMaxLines(2);
                break;
            case AlbumNew.Channel.TYPE_MOVIE:
                if (!TextUtils.isEmpty(block.getSubTitle())) {// 副标题不为空
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            case AlbumNew.Channel.TYPE_DOCUMENT_FILM:
                if (block.getType() == AlbumNew.Type.VRS_MANG &&
                        !TextUtils.isEmpty(block.getSubTitle())) {// 专辑且副标题不为空
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
            default:
                if (!TextUtils.isEmpty(block.getSubTitle())) {
                    titleView.setSingleLine(true);
                    titleView.setMaxLines(1);
                    subTitleView.setVisibility(View.VISIBLE);
                    subTitleView.setText(block.getSubTitle());
                } else {
                    subTitleView.setVisibility(View.GONE);
                    titleView.setSingleLine(false);
                    titleView.setMaxLines(2);
                }
                break;
        }
    }

    public static Channel getVipChannel(ChannelListBean channelList) {
        if (channelList == null) {
            return null;
        }
        ArrayList<Channel> list = channelList.getChannelList();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId() == AlbumNew.Channel.TYPE_VIP) {
                return list.get(i);
            }
        }
        return null;
    }
}
